import { fetchData } from '@/services/request';
import { ArticleModel } from '@/models/article.model';

const articleApi = '/api/article';

export function getAllArticle(): Promise<ArticleModel[]> {
  return fetchData({
    url: articleApi,
    method: 'get',
  });
}

export function getArticleDetail(id: number): Promise<ArticleModel> {
  return fetchData({
    url: `${articleApi}/detail`,
    method: 'get',
    params: {
      id,
    },
  });
}

export function addArticle(): Promise<ArticleModel> {
  return fetchData<ArticleModel>({
    url: articleApi,
    method: 'put',
  });
}

export function delArticle(id: number) {
  return fetchData({
    url: articleApi,
    method: 'delete',
    data: {
      id,
    },
  });
}

export function modifyArticle(data: ArticleModel) {
  return fetchData({
    url: articleApi,
    method: 'post',
    data,
  });
}
